//package com.huai.demo_test1.rocketmq;
//
//import com.huai.demo_test1.config.JmsConfig;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
//import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
//import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
//import org.apache.rocketmq.client.exception.MQClientException;
//import org.apache.rocketmq.common.consumer.ConsumeFromWhere;
//import org.apache.rocketmq.common.message.Message;
//import org.springframework.stereotype.Component;
//
//import java.nio.charset.StandardCharsets;
//
///**
// * @author 淮晓欢
// * @date 2022/1/3
// **/
//@Slf4j
//@Component
//public class ConsumerTest {
//
//    public static final String CONSUMER_GROUP = "test_consumer";
//
//    public ConsumerTest() throws MQClientException {
//        /*
//         * 消费者实体对象
//         */
//        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(CONSUMER_GROUP);
//        consumer.setNamesrvAddr(JmsConfig.NAME_SERVER);
//        //消费模式， 一个新的订阅组第一次启动从队列的最后位置开始消费，后续接着上次的位置
//        consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET);
//        consumer.subscribe(JmsConfig.TOPIC, "*");
//        consumer.registerMessageListener((MessageListenerConcurrently) (msgs, context) -> {
//            for (Message msg : msgs) {
//                String body = new String(msg.getBody(), StandardCharsets.UTF_8);
//                log.info("Consumer-获取消息-主题topic为={}, 消费消息为={}", msg.getTopic(), body);
//            }
//            return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
//        });
//        consumer.start();
//        log.info("消费者 启动成功======");
//    }
//}
